//
//  STApplicationFormTableViewCell.m
//  赛拓
//
//  Created by 王磊 on 8/13/16.
//  Copyright © 2016 立金所. All rights reserved.
//

#import "STApplicationFormTableViewCell.h"
#import "STApplicationFormBean.h"
@interface STApplicationFormTableViewCell()

@property (nonatomic ,strong) UILabel *titleLabel;

@property (nonatomic ,strong) UIButton *add;

@property (nonatomic ,strong) UIView *singleLine;
@end
@implementation STApplicationFormTableViewCell

- (void)configSubViews {
    [super configSubViews];
    
    
    
    UILabel *titleLabel = [UILabel new];
    
    self.titleLabel = titleLabel;
    
    titleLabel.font = ST_16_FONT;
    
    titleLabel.textColor = ST_BLACK_COLOR;
    
    [self addSubview:titleLabel];
    
    UIButton *add = [UIButton buttonWithType:UIButtonTypeCustom];
    
    self.add = add;
    
    [add setImage:[UIImage imageNamed:@"添加－30"] forState:UIControlStateNormal];
    [add setImage:[UIImage imageNamed:@"添加－30"] forState:UIControlStateHighlighted];
    
    [add addTarget:self action:@selector(addImage) forControlEvents:UIControlEventTouchUpInside];
    
    add.backgroundColor = [UIColor redColor];
    
    [self addSubview:add];
    
    UIView *singleLine = [UIView new];
    
    singleLine.backgroundColor = ST_BLACK_COLOR;
    
    self.singleLine = singleLine;
    
    [self addSubview:singleLine];
}

- (void)updateData:(id)data {
    
    STApplicationFormBean *form = data;
    
    self.titleLabel.text = [NSString stringWithFormat:@"* %@",form.title];
    
    if ([form.icon isKindOfClass:[NSString class]]) {
        
        self.add.hidden = false;
    } else {
        
        self.add.hidden = true;
    }
}
- (void)addImage {
    
    [self.mDelegate onItemClick:STItemClickTypeCredentialsUpload withData:nil forIndexPath:self.indexPath];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    CGFloat margin = 20 * ST_RATE;
    
    CGFloat size = 100;
    
    self.titleLabel.frame = CGRectMake(margin, 0, self.k_width - margin * 2, 40);
    
    self.singleLine.frame = CGRectMake(margin, CGRectGetMaxY(self.titleLabel.frame), self.k_width - margin * 2, 0.5);
    
    self.add.frame = CGRectMake(margin, CGRectGetMaxY(self.titleLabel.frame) + margin, size, size);
    
}

@end
